import configparser
import os


class ConfHandler():

    def conf_handler(self,conf_type):
        base_path = os.path.dirname(os.path.dirname(__file__))
        a_path = os.path.join(base_path, "my.ini")
        # print("a_path:",a_path)
        # 创建管理对象
        conf = configparser.ConfigParser()
        # 读ini文件
        conf.read(a_path, encoding="utf-8")
        # 获取某一个section
        items = conf.items(conf_type)
        mysql_conf = {}
        for item in items:
            mysql_conf[item[0]] = item[1]

        return mysql_conf

if __name__ == '__main__':
    cf = ConfHandler()
    print(cf.conf_handler("run_env"))
    print(cf.conf_handler("mysql"))
